<?php
require_once(Kohana::find_file('vendor','phprpc/phprpc_server'));
/**
 * Created by PhpStorm.
 * User: locove
 * Date: 14-10-9
 * Time: 上午9:54
 * Note: 为供应商系统提供数据的服务端
 */
class Controller_Accountsystemapi extends Controller
{
    protected $server;
    public function before(){
        $this->server=new PHPRPC_Server();
    }

    /**
     * 测试
     */
    public function action_index(){
        function getData($param)
        {
            echo $param,'ok';
            return $param;
        }
        $this->server->add('getData','getData');
    }
    /**
     * 获取采购单id
     */
    public function action_putNewerpIdByName(){
        $this->server->add('putNewerpIdByName','accountsystemapiserver','getData');
    }

    /**
     * 根据采购单id获取采购单信息
     */
    public function action_putDataById(){
        $this->server->add('putDataById','accountsystemapiserver','getData');
    }

    public function after(){
        $this->server->start();
    }

    /**
     * 获取用户信息
     * @author zhjx
     */
    public function action_putUsers()
    {
       $this->server->add('getUsersBy','accountsystemapiserver','getData');
    }


    /**
     * 获取付款方式
     */
    public function action_putPayways()
    {
        $this->server->add('getPaywaysBy','accountsystemapiserver','getData');
    }

    /**
     * 获取付款帐号信息
     */
    public function action_putPayaccounts()
    {
        $this->server->add('getPayaccounts','accountsystemapiserver','getData');
    }

    /**
     * 回写付款信息
     */
    public function action_writePay()
    {
        $this->server->add('doPoPay','accountsystemapiserver','putData');
    }

    public function action_query0()
    {
        function getData($sql)
        {
          if($sql)
          {
            return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array();
          }
        }

        $this->server->add('getData');
    }

    public function action_query1()
    {
        function getData($sql)
        {
            if($sql)
            {
                return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array();
            }
        }

        $this->server->add('getData');
    }


    public function action_query2()
    {
        function getData($sql)
        {
            if($sql)
            {
                return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array();
            }
        }

        $this->server->add('getData');
    }


    public function action_query3()
    {
        function getData($sql)
        {
            if($sql)
            {
                return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array();
            }
        }

        $this->server->add('getData');
    }


    public function action_query4()
    {
        function getData($sql)
        {
            if($sql)
            {
                return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array();
            }
        }

        $this->server->add('getData');
    }

    public function action_query5()
    {
        function getData($sql)
        {
            if($sql)
            {
                return DB::query(Database::SELECT,$sql)->execute('newerp')->as_array();
            }
        }

        $this->server->add('getData');
    }

    /**
     * 给供应商系统提供一个共用的SQL调用方法
     */
    public function action_executeSql() {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_server'));

        $server = new PHPRPC_Server();

        $server->add('executeSql','accountsystemapiserver','executeSql');

        $server->start();
    }
}